package tankgame4;

import java.util.Vector;

public class Hero extends Tank {
    Shot shot = null;
    //建一个Vector来保存多颗子弹
    Vector<Shot> shots = new Vector<>();

    public Hero(int x, int y) {
        super(x, y);
    }

    public void shotEnemyTank() {
        //最多只能有5颗子弹
        if (shots.size() == 5 ){
            return;
        }

        //创建shot对象，根据Hero对象的位置和方向来创建
        switch (getDirect()) {
            case 0:
                shot = new Shot(getX() + 20, getY(), 0);
                break;
            case 1:
                shot = new Shot(getX() + 60, getY() + 20, 1);
                break;
            case 2:
                shot = new Shot(getX() + 20, getY() + 60, 2);
                break;
            case 3:
                shot = new Shot(getX(), getY() + 20, 3);
                break;
        }

        //把新创建的shot放入shots
        shots.add(shot);
        //启动shot线程
        new Thread(shot).start();
    }
}
